<?php

/**
 * @Author: king
 * @Date:   2019-03-24 15:04:03
 * @Last Modified by:   king
 * @Last Modified time: 2019-03-24 15:26:23
 */

namespace App\Http\Controllers\Api\v1\Article;

use App\Http\Controllers\Api\BaseController;
use App\Models\Api\MiddleInformant;
use App\Models\Api\User;
use Illuminate\Http\Request;

/**评论举报相关接口
 * Class ComplaintComment
 * @package App\Http\Controllers\Api\v1
 */
class ComplaintComment extends BaseController
{

    public function index(Request $request)
    {
        if (!$request->isMethod('post')) {
            return show(config('code.error'), '未知操作', [], 403);
        }

        $comment_id = $request->input('comment_id');
        $content    = $request->input('content');
        $type =  $request->input('type');
        $arr = [
            1 => '垃圾营销',
            2 => '涉黄信息',
            3 => '有害信息',
            4 => '违法信息',
            5 => '侵害人身权益',
            6 => '其他原因',
        ];

        $offset = array_search($content, $arr) ?? 0;

        $arr = [
            'comment_id' => $comment_id,
            'info_id'    => $offset,
            'type'=>$type,
            'uid'        => $request->uid,
        ];

        try
        {
            (new MiddleInformant())->insert($arr);
        } catch (\Exception $e) {
            \Log::info($e->getMessage());

            return show(config('code.error'), '举报失败');
        }

        return show(config('code.success'), '举报成功');
    }
}
